<?php
declare (strict_types=1);

namespace app\exam\logic;

use app\common\exception\LogicException;
use app\exam\model\Option as OptionModel;


/**
 * 试题逻辑
 */
class Option extends OptionModel
{

	/**
	 * 获取试题选项
	 * Author 亓官雨树<lucky.max@foxmail.com>
	 * Date 2021-02-04
	 * @param  integer $topic_id   [description]
	 * @param  integer $topic_type [description]
	 * @return [type]              [description]
	 */
	public function getTopicOptions($topic_id = 0, $topic_type = 1, $analyze = true)
	{
		$field   = 'id,key,value';
		$analyze && $field .= ',is_right';
		$options = $this->field($field)->whereTopicId($topic_id)->whereTopicType($topic_type)->select()->each(function($i)
		{
			$i->material = app(Common::class)->parseMaterial($i->value?:'');
			$i->value 	 = app(Common::class)->removeMaterial($i->value?:'');
		});
		
		return $options;
	}

}